<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Model\Admin;
class LoginController extends Controller
{	

	//登陆页面
    public function login(){
    	return view('admin.login');
    }

    //登陆
    public function doLogin(Request $request){
    	$name = $request->name;
    	$password = md5($request->password);
    	// var_dump($password);die;
    	$model = new Admin();
    	$data=$model->login($name);
    	// dd($data);die;
    	if(!empty($data)){
    		if($data->password == $password){
    			$request->session()->put('admin',$data);
    			return redirect('admin/index');
    		}else{
    			return back()->with('msg',"用户名或密码错误");
    		}
    	}else{
    		return back()->with('msg',"用户名不存在");
    	}
    }

    public function Logout()
    {
        session()->forget('admin');
        return redirect('/admin/login');
    }
}
